home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 001 / halfbrite / halfbrite.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  10KB  |  290 lines

  1. /*
  2.  * Article 639 of net.micro.amiga:
  3.  * ion: version B 2.10.2 9/17/84 chuqui version 1.9 3/12/85; site unisoft.UUCP
  4.  * Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site amiga.amiga.UUCP
  5.  * Path: unisoft!dual!lll-crg!gymble!umcp-cs!seismo!caip!topaz!packard!ihnp1!ihnp4!nsc!pyramid!amiga!bobp
  6.  * From: bobp@amiga.UUCP (Robert S. Pariseau)
  7.  * Newsgroups: net.micro.amiga
  8.  * Subject: Fun with 6 Bit Planes (SOURCE)
  9.  * Message-ID: <214@amiga.amiga.UUCP>
  10.  * Date: 9 Nov 85 10:15:42 GMT
  11.  * Date-Received: 18 Nov 85 19:15:06 GMT
  12.  * Reply-To: bobp@snake.UUCP (Robert S. Pariseau)
  13.  * Organization: Commodore-Amiga Inc., 983 University Ave #D, Los Gatos CA 95030
  14.  * Lines: 270
  15.  * 
  16.  * 
  17.  * TITLE:  Fun With 6 Bit Planes (SOURCE)
  18.  * 
  19.  * There are lots of fun things you can do in 6 bit planes on the Amiga,
  20.  * including Hold and Modify color displays and dual-playfield mode
  21.  * with two separately scroll-able, completely independent, 8 color
  22.  * playfields with overlay and transparency.
  23.  * 
  24.  * But tonight I'm going to discuss something you don't already know about
  25.  * your Amiga -- even if you've read all the tech manuals cover to cover.
  26.  * 
  27.  * The specs for the Amiga say that in a completely static, low-resolution
  28.  * display, with nothing fancy going on (like Hold and Modify), you can
  29.  * display up to 32 colors simultaneously out of a pallette of 4096.
  30.  * 
  31.  * Well not quite.
  32.  * 
  33.  * You can actually display up to 64 distinct colors out of that pallette
  34.  * of 4096!  Yes, an unlimited choice of any of 64 colors at each pixel
  35.  * in the screen!
  36.  * 
  37.  * Have I got your attention?
  38.  * 
  39.  * Welcome to Extra-Half-Brite mode.
  40.  * 
  41.  * The Amiga display hardware automatically enters Extra-Half-Brite mode
  42.  * whenever you select a 6 plane display (which must be low res due to
  43.  * the hardware) and have NOT selected either Hold and Modify or Dual
  44.  * Playfield mode.
  45.  * 
  46.  * The graphics kernel software further enforces the rule that you must
  47.  * set the EXTRA_HALFBRITE flag in the ViewModes for the ViewPort (Screen
  48.  * in Intution lingo) or it will automatically trim your screen down to
  49.  * 5 planes.  This is done both for backward compatability and to insure
  50.  * support in future Amiga architectures.
  51.  * 
  52.  * Consider the playfield data bits for a given pixel.  The bits from the
  53.  * first five planes form a color register selector for that pixel,
  54.  * allowing you to choose among the 32 color registers in the Amiga.  The
  55.  * bit from the sixth plane is interpreted as follows:
  56.  *   0 -- Use the color in the selected color register just as specified.
  57.  * 
  58.  *   1 -- Take the color in the selected color register, shift each of
  59.  *        its R, G, and B components right one bit, and use the new
  60.  *        color value thus formed.
  61.  * 
  62.  * The net result is as if you had 64 color registers where the colors
  63.  * in the top 32 were "half-intensity" counterparts of the colors in the
  64.  * bottom 32!
  65.  * 
  66.  * Of course, that means there is a dependency between the choice of
  67.  * colors in the 32 real registers and the resulting colors in the
  68.  * 32 psuedo-registers.  Nevertheless, I assert we have as much right
  69.  * to claim 64 colors on screen as IBM has to claim 16 colors from a
  70.  * monitor that is physically capable of producing only 8 colors at
  71.  * 2 intensities!  At least we can select our 32 colors out of a
  72.  * pallatte of 4096!
  73.  * 
  74.  * Note also that, since fractional color components have no meaning
  75.  * in the hardware, there are several distinct real colors that produce
  76.  * the same extra color.  For instance (in hex):
  77.  *   888 --> 444,    988 --> 444,   898 --> 444,   999 --> 444,  etc.
  78.  * 
  79.  * Despite all this quibbling, with a little thought it's easy to see
  80.  * how you can choose a set of 32 real colors to make sure all 64 real
  81.  * plus extra colors are distinct.  And they are every-pixel-addressable!
  82.  * 
  83.  * Why have we kept this little jewel a secret?  No, it's not that we
  84.  * were planning to lull the competition into complacency and then
  85.  * spring an instant double of the Amiga's color capacity on them.
  86.  * 
  87.  * Actually, the rev of the custom chips in which this worked was the
  88.  * last rev before we went into production.  Thus the info was too
  89.  * late to make it into the current version of the Amiga Hardware
  90.  * Manual.
  91.  * 
  92.  * Some caveats.  Although ALL the consumer machines have the necessary
  93.  * chip rev, there are some older developer's machines out there which
  94.  * can't do this trick.  BEWARE!  Some of the store demo units come out
  95.  * of that older developer's stock and won't contain the Extra-Half-Brite
  96.  * hardware.  Note that you can't hurt anything by running such a program
  97.  * on an older machine -- the values in the 6th bit plane will simply
  98.  * be ignored.
  99.  * 
  100.  * Also the V1.0 printer device will not correctly handle this trick
  101.  * for color printing -- it works fine in V1.1.
  102.  * 
  103.  * The sample program below shows Extra-Half-Brite mode in operation.
  104.  */
  105.  
  106. /*
  107.  * 
  108.  * -------------------------Program Notes
  109.  * 
  110.  * The Extra program will compile and link cleanly using the native
  111.  * Amiga Lattice C tools on the standard V1.0 C disk.  The Make
  112.  * script in the examples directory will do all the work for you.
  113.  * 
  114.  * I suggest you copy your source file into ram disk, cd over to your
  115.  * C development disk, and type
  116.  *   1> execute Make ram:Extra    [assumes you are where Make is]
  117.  * 
  118.  * Afterwards, copy the resulting Extra program back out of ram: to
  119.  * someplace safe from power failures.
  120.  * 
  121.  * The program itself is pretty straightforward.  It opens a 6 plane
  122.  * low res custom screen and then opens a window in that screen.
  123.  * 64 color patches are then drawn into that window with color register
  124.  * usage increasing left to right then top to bottom from 0 to 63.  For
  125.  * simplicity, this program uses the default color pallette supplied
  126.  * with the new screen.
  127.  * 
  128.  * Due to the EXTRA_HALFBRITE special ViewMode in the screen definition,
  129.  * the bottom 4 rows of color should be the half intensity counterparts
  130.  * of the corresponding patches in the top 4 rows.
  131.  * 
  132.  * The program waits for a CLOSEWINDOW message from Intution, then
  133.  * cleans up and goes away.
  134.  * 
  135.  * -------------------------Program Source Follows:
  136.  * 
  137.  */
  138.  
  139. /***********************************************************************
  140.  *  Extra -- Program to demonstrate Extra-Half-Brite graphics display
  141.  *           mode on the Amiga.
  142.  *
  143.  *  Dale Luck    -- October, 1985
  144.  *  Bob Pariseau -- November 8, 1985  (Editorial changes)
  145.  *
  146.  **********************************************************************/
  147.  
  148. #include <exec/types.h>
  149. #include <exec/tasks.h>
  150. #include <exec/libraries.h>
  151. #include <exec/devices.h>
  152. #include <devices/keymap.h>
  153. #include <graphics/copper.h>
  154. #include <graphics/display.h>
  155. #include <graphics/gfxbase.h>
  156. #include <graphics/text.h>
  157. #include <graphics/view.h>
  158. #include <graphics/gels.h>
  159. #include <graphics/regions.h>
  160. #include <hardware/blit.h>
  161. #include <intuition/intuition.h>
  162. #include <intuition/intuitionbase.h>
  163.  
  164.  
  165. struct   GfxBase        *GfxBase;         /* Export library base pointers */
  166. struct   IntuitionBase  *IntuitionBase;
  167.  
  168. struct   Screen   *colscreen;             /* Pointers to new screen and   */
  169. struct   Window   *wndo;                  /* window.                      */
  170.  
  171. struct   NewScreen newscreen;             /* OpenX() arguments for new    */
  172. struct   NewWindow newwindow;             /* screen and window.           */
  173.  
  174. struct   TextAttr Font =
  175. {
  176.    "topaz.font",            /* Use standard system font */
  177.    8,
  178.    FS_NORMAL,
  179.    FPF_ROMFONT,
  180. };
  181.  
  182. struct IntuiMessage *message;
  183.  
  184.  
  185.  
  186. main()
  187. {
  188.    if ((IntuitionBase = (struct  IntuitionBase *)OpenLibrary("intuition.library", 0)) == 0)
  189.    {
  190.       printf("WOT !  No Intuition ???\n");
  191.       exit();
  192.    }
  193.  
  194.    if ((GfxBase = (struct   GfxBase *)OpenLibrary("graphics.library", 0)) == 0)
  195.    {
  196.       printf("Oh ! No Graphics??\n");
  197.       CloseLibrary(IntuitionBase);
  198.       exit();
  199.    }
  200.  
  201. /* values for new screen */
  202.    newscreen.LeftEdge       = 0;
  203.    newscreen.TopEdge        = 0;
  204.    newscreen.Width          = 320;
  205.    newscreen.Height         = 200;
  206.    newscreen.Depth          = 6;
  207.    newscreen.DetailPen      = 0;
  208.    newscreen.BlockPen       = 1;
  209.    newscreen.ViewModes      = EXTRA_HALFBRITE;
  210.    newscreen.Type           = CUSTOMSCREEN;
  211.    newscreen.Font           = &Font;
  212.    newscreen.DefaultTitle   = "Six Planes Low Res";
  213.    newscreen.Gadgets        = NULL;
  214.    
  215.    colscreen = (struct Screen *)OpenScreen(&newscreen);
  216.    if (colscreen == 0)
  217.    {
  218.       printf("Screen Failed !!!!!\n");
  219.       CloseLibrary(GfxBase);
  220.       CloseLibrary(IntuitionBase);
  221.       exit();
  222.    }
  223.  
  224. /* values for new window */
  225.    newwindow.LeftEdge      = 0;
  226.    newwindow.TopEdge       = 15;
  227.    newwindow.Width         = 320;
  228.    newwindow.Height        = 185;
  229.    newwindow.DetailPen     = 0;
  230.    newwindow.BlockPen      = 1;
  231.    newwindow.Flags         = ACTIVATE | SIMPLE_REFRESH | WINDOWCLOSE;
  232.    newwindow.IDCMPFlags    = CLOSEWINDOW;
  233.    newwindow.FirstGadget   = NULL;
  234.    newwindow.CheckMark     = NULL;
  235.    newwindow.Title         = "Extra-Half-Brite Colors!";
  236.    newwindow.Screen        = colscreen;
  237.    newwindow.BitMap        = NULL;
  238.    newwindow.MinWidth      = 20;
  239.    newwindow.MinHeight     = 20;
  240.    newwindow.MaxWidth      = 320;
  241.    newwindow.MaxHeight     = 200;
  242.    newwindow.Type          = CUSTOMSCREEN;
  243.  
  244.    wndo = (struct Window *)OpenWindow(&newwindow);
  245.    if (wndo == 0)
  246.    {
  247.        printf("Window failed!!!\n"); 
  248.        CloseScreen(colscreen);
  249.        CloseLibrary(GfxBase);
  250.        CloseLibrary(IntuitionBase);
  251.        exit();
  252.    }
  253.  
  254.    setup(wndo->RPort);
  255.  
  256.    FOREVER
  257.    {
  258.       WaitPort(wndo->UserPort);
  259.       message = (struct IntuiMessage *)GetMsg(wndo->UserPort);
  260.       if(message->Class == CLOSEWINDOW)
  261.       {
  262.          ReplyMsg(message);       /* Can't reply till done using */
  263.          CloseWindow(wndo);
  264.          CloseScreen(colscreen);
  265.          CloseLibrary(GfxBase);
  266.          CloseLibrary(IntuitionBase);
  267.          exit();
  268.       }
  269.       ReplyMsg(message);
  270.    }
  271.  
  272. }
  273.  
  274. setup(rastp)
  275. struct RastPort *rastp;
  276. {
  277.    USHORT   countx;
  278.    USHORT   county;
  279.    USHORT   color;
  280.  
  281.    for (countx = 0; countx < 8; countx++)
  282.       for (county = 0; county < 8; county++)
  283.       {
  284.          color = (county<<3) + countx;
  285.          SetAPen(rastp,color);
  286.          RectFill(rastp,countx*35+10,county*20+15,countx*35+45,county*20+35);
  287.       }
  288. }
  289.  
  290.